﻿using BarcodeDelay.business;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BarcodeDelay.view
{
    public partial class FrmSetting : Form
    {
        public FrmSetting()
        {
            InitializeComponent();
        }

        private void FrmSetting_Load(object sender, EventArgs e)
        {
            this.txtTransfer.Text = MemberInfo.Instance.templeteTransfer;
            this.txtAssign.Text = MemberInfo.Instance.templeteAssign;
            this.txtQS.Text = MemberInfo.Instance.templeteQS;
            this.txtReturn.Text = MemberInfo.Instance.templeteReturn;
            this.txtCuijian.Text = MemberInfo.Instance.templeteCuijian;
            this.splitContainer4.SplitterDistance = this.splitContainer4.Height / 2;
            //this.splitContainer6.SplitterDistance = this.splitContainer6.SplitterWidth / 2;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string strContent = this.txtTransfer.Text.Replace("~","");
                if (strContent.Length < 10)
                {
                    MessageBox.Show("中转模板不正常");
                    return;
                }
                MemberInfo.Instance.templeteTransfer = strContent;
                string strContentAssgin = this.txtAssign.Text.Replace("~", ""); ;
                if(strContentAssgin.Length<10)
                {
                    MessageBox.Show("派件模板不正常");
                    return;
                }
                MemberInfo.Instance.templeteAssign = strContentAssgin;

                string strContentQS = this.txtQS.Text.Replace("~", ""); ;
                if (strContentQS.Length < 10)
                {
                    MessageBox.Show("催签收模板不正常");
                    return;
                }

                string strContentReturn = this.txtReturn.Text.Replace("~", ""); ;
                if (strContentReturn.Length < 8)
                {
                    MessageBox.Show("拦截退回模板不正常");
                    return;
                }

                string strContentCuijian = this.txtCuijian.Text.Replace("~", ""); ;
                if (strContentCuijian.Length < 8)
                {
                    MessageBox.Show("退件模板不正常");
                    return;
                }

                MemberInfo.Instance.templeteReturn = strContentReturn;
                MemberInfo.Instance.templeteQS = strContentQS;
                MemberInfo.Instance.templeteCuijian = strContentCuijian;
                FileStream bFile = new FileStream(StoParams.Instance.templetePath, FileMode.Create);
                StreamWriter swb = new StreamWriter(bFile);
                swb.Write(strContent+"~"+ strContentAssgin + "~" + strContentQS + "~" + strContentReturn + "~" + strContentCuijian);
                swb.Close();
                swb = null;


                this.Close();

            }
            catch(Exception ex)
            {
                MessageBox.Show("模板不正常");
            }
        }

        private void splitContainer1_Panel2_Paint(object sender, PaintEventArgs e)
        {

        }
    }
}
